package cn.jdy.platform.tag;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import cn.jdy.djgaj.entity.DjgajNews;
import cn.jdy.djgaj.sevice.DjgajNewsService;
import cn.jdy.framework.util.SpringContextUtils;
import cn.jdy.lhkgaj.entity.LhkgajNews;
import cn.jdy.lhkgaj.entity.LhkgajWorks;
import cn.jdy.lhkgaj.service.LhkgajNewsService;
import cn.jdy.lhkgaj.service.LhkgajWorksService;
import cn.jdy.xzgaj.entity.XzgajNews;

/**
 * 文章类型的自定义标签
 * @description 将文章，新闻这种常规性的功能通过自定义标签后获取内容
 * @author ningqian
 * @date   2016-10-27
 */
public class workslhkgajListTag extends SimpleTagSupport implements java.io.Serializable{
	private static final long serialVersionUID = 1L;
	private String var;
	private boolean pid=false;// 父栏目id
	private Long columnid;// 栏目id
	private int limitMax=50; //默认一次最多查询记录数
	private String style;// 显示样式
	
	private boolean img=false;// 是否过滤封面图片
	private int statuses=0;//加入状态

	@Override
	public void doTag() throws JspException, IOException {
		LhkgajWorksService newsService = SpringContextUtils.getBean(LhkgajWorksService.class);
	  
		List<LhkgajWorks> list = null;
	//	if(pid){// 按照父分类查询
	//	  list = newsService.findbyPid(columnid, 0, limitMax, img);
	//	}else{// 按照栏目查询
	//	  list = newsService.findbytype(columnid, 0, limitMax, img);
		//}
	//	if((!pid)&&(statuses==1)){//状态为1的时候查询状态加入置顶
		LhkgajWorks ro=new LhkgajWorks();
		ro.setiDisplayStart(0);
		ro.setiDisplayLength(limitMax);
			list = newsService.query(ro);
		//}
		//if((!pid)&&(statuses==2)){//状态为2的时候查询状态为1有效、3置顶的news中imgurl有值的前limitmax
		//	list = newsService.findbyNstatus(columnid, 0, limitMax, img, statuses);
	//	}
		
		
		
		/*** 统计还要多少要签收  开始 */
		for(LhkgajWorks x : list){
			List<String> realAssos = new ArrayList<String>();
			List<String> notAssos = new ArrayList<String>();
			String status = x.getSignStatus();
			int tempIndex=0;
			String[] zhiduis = null;
			String[] assos = null;
			if(null != x.getSignDepartment() && !"".equals(x.getSignDepartment())){
				assos = x.getSignDepartment().split(";");
			}
			int len = 0,cnt=0;
			//公安-签收状态有别于特警，直接加入签收用户名，用,逗号分隔
			if(status!=null && status!=""){
				zhiduis = status.split(",");//已签收单位String数组
			}
			if(null != assos){
				for(int i=0;i<assos.length;i++){
					if((assos[i]!=null)){
						realAssos.add(cnt, assos[i]);
						//未签收
						if(zhiduis!=null && zhiduis.length>0){
							int tempCnt=0;
							for(int it=0;it<zhiduis.length;it++){
								if(!(assos[i].equals(zhiduis[it]))){
									tempCnt++;
								}
							}
							if(tempCnt==zhiduis.length){
								notAssos.add(tempIndex, assos[i]);
								tempIndex++;
							}
						}else{
							notAssos.add(cnt, assos[i]);
						}
						cnt++;
					}
				}
			}
			 if(realAssos.size()>0){
				 x.setSignStatus(notAssos.size()+"");//用这个字段迭代到前台			
				}else{
					x.setSignStatus("-1");
				}
			
		}
		/***  统计还要多少要签收  结束*/
		
		Iterator<LhkgajWorks> ite = list.iterator();
		// 进行迭代
		while (ite.hasNext()) {
			Object obj = ite.next();
			getJspContext().setAttribute(var, obj);
			//输出标签体
			getJspBody().invoke(null);
		}
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}
	


  public int getLimitMax() {
    return limitMax;
  }

  public void setLimitMax(int limitMax) {
    this.limitMax = limitMax;
  }

  public Long getColumnid() {
    return columnid;
  }

  public void setColumnid(Long columnid) {
    this.columnid = columnid;
  }

  public boolean getPid() {
    return pid;
  }

  public void setPid(boolean pid) {
    this.pid = pid;
  }

  public boolean getImg() {
    return img;
  }

  public void setImg(boolean img) {
    this.img = img;
  }

public int getStatuses() {
	return statuses;
}

public void setStatuses(int statuses) {
	this.statuses = statuses;
}
 


}
